<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="UTF-8">
    <th:block th:include="include :: header('新增分类编码')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-flcode-add">
        <input id="treeId" name="parentId" type="hidden" th:value="${flcode.flId}"   />
        <div class="form-group">
            <label class="col-sm-3 control-label">上级分类编码名称：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" onclick="selectflCodeTree()" id="treeName" readonly th:value="${flcode.flName}">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">分类编码名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="flName" autocomplete="off" id="flName" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">分类编码数字标识：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="flCode" autocomplete="off" placeholder="如：01" id="flCode" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">完整分类编码：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="flCodecomplete" id="flCodecomplete" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">显示排序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="orderNum" placeholder="输入正整数" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">类型：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('base_flcode_type')}">
                    <input type="radio" th:id="${dict.dictCode}" name="flType" th:value="${dict.dictValue}" th:checked="${dict.default}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">分类编码状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                    <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea class="form-control" type="text" rows="3" name="remark"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">

    var prefix = ctx + "base_";
    var fl_Codecomplete = [[${flcode.flCodecomplete}]];

    $("#form-flcode-add").validate({
        onkeyup: false,
        rules:{
            flName:{
                remote: {
                    url: prefix + "/checkflNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "parentId": function() {
                            return $("input[name='parentId']").val();
                        },
                        "flName" : function() {
                            return $.common.trim($("#flName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            orderNum:{
                digits:true
            }
        },
        messages: {
            flName: {
                remote: "同级下的分类编码名称已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-flcode-add').serialize());
        }
    }

    /**
     *flCodecomplete 完整分类编码显示 1s执行一次
     */
    setInterval(function (){
        if($.common.isNotEmpty(fl_Codecomplete)){
            if($("#flCode").val()!==''){
                $("#flCodecomplete").attr('value',fl_Codecomplete+"-"+$("#flCode").val());
            }else{
                $("#flCodecomplete").attr('value','');
            }
        }else{
            $("#flCodecomplete").attr('value','上级无完整分类编码，请先添加！');
        }
    },1000)

    /*分类编码管理-新增-选择父分类编码树*/
    function selectflCodeTree() {
        var options = {
            title: '分类编码选择',
            width: "380",
            url: prefix + "/selectFlCodeTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }
</script>
</body>
</html>
